/**
 * 
 */
package com.shequan.pbinfo.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.ailk.dazzle.util.data.JSONUtils;
import com.shequan.common.bean.ResultDataStruct;
import com.shequan.common.bean.ViewTextConstans;
import com.shequan.pbinfo.bean.pojo.GovArea;
import com.shequan.pbinfo.bean.pojo.School;
import com.shequan.pbinfo.service.GovAreaService;
import com.shequan.pbinfo.service.SchoolService;

/**
 * <P>
 * Copyright 2012.
 * </p>
 * <P>
 * All Rights Reserved.
 * </p>
 * 
 * @author YuJF
 * @version 1.0, 2012-3-7
 * @see com.shequan.pbinfo.controller.PublicController
 * @since 1.0
 */
@Controller
@RequestMapping("/pbinfo")
public class PublicController {
	private static Logger log = Logger.getLogger(PublicController.class);

	private GovAreaService govAreaService;
	private SchoolService schoolService;

	public void setSchoolService(SchoolService schoolService) {
		this.schoolService = schoolService;
	}

	public void setGovAreaService(GovAreaService govAreaService) {
		this.govAreaService = govAreaService;
	}

	/**
	 * 加载地区列表
	 * 
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping(value = "/locationinfo")
	public void getLocationInfo(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ResultDataStruct<List<GovArea>> rds = null;
		try {
			rds = govAreaService.queryLocationInfo();
		} catch (Exception e) {
			if (rds == null) {
				rds = new ResultDataStruct<List<GovArea>>();
			}
			log.error("", e);
			rds.setSuccess(false);
			rds.setMessage(ViewTextConstans.UNKNOW_ERROR_MSG);
		}
		String jsonData = JSONUtils.bean2JsonString(rds);
		response.getWriter().print(jsonData);
	}
	
	/**
	 * 加载学校信息
	 * @param request
	 * @param response
	 * @throws Exception
	 */
	@RequestMapping(value="/schoolinfo")
	public void getSchoolInfo(HttpServletRequest request,
			HttpServletResponse response) throws Exception {
		ResultDataStruct<List<School>> rds = null;
		try {
			rds=schoolService.querySchoolInfo(); 
		} catch (Exception e) {
			if (rds == null) {
				rds = new ResultDataStruct<List<School>>();
			}
			log.error("", e);
			rds.setSuccess(false);
			rds.setBusiSuccess(false);
			rds.setMessage(ViewTextConstans.UNKNOW_ERROR_MSG);
		}
		String jsonData = JSONUtils.bean2JsonString(rds);
		response.getWriter().print(jsonData);
	}
}
